package com.glamour.hlcity.component.framework.registry.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;

import com.glamour.hlcity.common.util.ListUtil;
import com.glamour.hlcity.component.framework.registry.ServiceRegistry;

/**
 * 本地服务注册
 * @author zhaoxing.liuzx
 *
 */
public class LocalServiceRegistry extends ServiceRegistry {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public  <T> ServiceRegistry addService(T service){
		if(getLookup()==null){
			setLookup(Lookups.fixed(service));
		}else{
			Collection collection=getLookup().lookupAll(Object.class);
			List<Object> list=new ArrayList<Object>();
			list.addAll(collection);
			list.add(service);
			setLookup(Lookups.fixed(ListUtil.toArray(list)));
		}
		return this;
	}
	
	
	
}
